﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CodeKicker.BBCode;
using mdryden.Core.Localization;

namespace LastoRevival.ForumCode
{
	public class BBCodeConfiguration
	{
		public IList<BBTagReference> GetCodes()
		{
			var list = new List<BBTagReference>
			{
				GetBoldTag(),
				GetItalicTag(),
				GetUnderlineTag(),
				GetPreTag(),
				GetImageTag(),
				GetQuoteTag(),
				GetListTag(),
				GetUrlTag(),
			};

			return list;
		}

		public IList<BBTag> GetCodesAsList()
		{
			var list = new List<BBTag>();

			foreach (var item in GetCodes())
			{
				list.Add(item);
			}

			return list;
		}

		private BBTagReference GetBoldTag()
		{
			return new BBTagReference("b", "<strong>", "</strong>")
			{
				Description = LanguageLoader.GetWord("BoldTagDescription"),
				Sample = "[b]" + LanguageLoader.GetWord("BoldTagSampleText") + "[/b]"
			};
		}

		private BBTagReference GetItalicTag()
		{
			return new BBTagReference("i", "<em>", "</em>")
			{
				Description = LanguageLoader.GetWord("ItalicTagDescription"),
				Sample = "[i]" + LanguageLoader.GetWord("ItalicTagSampleText") + "[/i]"
			};
		}

		private BBTagReference GetUnderlineTag()
		{
			return new BBTagReference("u", "<span class=\"underline\">", "</span>")
			{
				Description = LanguageLoader.GetWord("UnderlineTagDescription"),
				Sample = "[u]" + LanguageLoader.GetWord("UnderlineTagSampleText") + "[/u]"
			};
		}
		
		private BBTagReference GetPreTag()
		{
			return new BBTagReference("pre", "<pre>", "</pre>")
			{
				Description = LanguageLoader.GetWord("PreTagDescription"),
				Sample = "[pre]" + LanguageLoader.GetWord("PreTagSampleText") + "[/pre]",
			};
		}

		private BBTagReference GetImageTag()
		{
			return new BBTagReference("img", "<img src=\"${content}\" />", "", false, true)
			{
				Description = LanguageLoader.GetWord("ImageTagDescription"),
				Sample = "[img]http://google.com/images/nav_logo91.png[/img]",
				SkipSampleRendering = true,
			};
		}

		private BBTagReference GetQuoteTag()
		{
			return new BBTagReference("quote", "<blockquote>", "</blockquote>")
			{
				Description = LanguageLoader.GetWord("QuoteTagDescription"),
				Sample = "[quote]" + LanguageLoader.GetWord("QuoteTagSampleText") + "[/quote]",
			};
		}
		
		private BBTagReference GetListTag()
		{
			return new BBTagReference("*", "<li>", "</li>", true, false)
			{
				Description = LanguageLoader.GetWord("ListTagDescription"),
				Sample = "[*]" + LanguageLoader.GetWord("ListTagSampleText1") + " [*]" + LanguageLoader.GetWord("ListTagSampleText2") + "",
			};
		}

		private BBTagReference GetUrlTag()
		{
			return new BBTagReference("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href"))
			{
				Description = LanguageLoader.GetWord("UrlTagDescription"),
				Sample = "[url=http://www.site.com]" + LanguageLoader.GetWord("UrlTagSampleText") + "[/url]",
			};
		}

	}
}